/* $Id: ipv6_dns_name.c,v 1.3 2004/11/24 08:27:33 sby Exp $ */

/* target : included C file for DNS routines */

#include "ipv6.h"
#include <string.h>


/* ----------------------------------------------------- */
/* get host name by IPv6 address                         */
/* ----------------------------------------------------- */


int
ipv6_dns_name(sa, host, hostlen)
  const struct sockaddr *sa;
  char *host;
  size_t hostlen;
{
  char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
  int ret;

  /* get remote host name */

  if ((ret = getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), sbuf,
	sizeof(sbuf), /*NI_NUMERICHOST |*/ NI_NUMERICSERV)) != 0)
    return ret;		/* could not get hostname */

  strncpy(host, hbuf, hostlen);
  host[--hostlen] = '\0';

  return ret;
}

